<template>
  <div class="register" :style="eabg">
    <!-- <img src="../../assets/login/loginbg.png" alt="" class="loginbg"> -->
    <div class="loginConent">
      <div class="loginTop">
        <img src="../../assets/login/logo.png" alt class="logo" />
        <div class="logotext">登录</div>
      </div>
      <div class="content">
        <div class="item">
          <!-- <img src="../../assets/login/tel.png" alt="" class="itemimg"> -->
          <span class="iconfont icon-lianxiren1 tel"></span>
          <input type="number" placeholder="请输入手机号" v-model="tel" />
        </div>
        <div class="item">
          <!-- <img src="../../assets/login/password.png" alt="" class="itemimg"> -->
          <span class="iconfont icon-login_mima"></span>
          <input type="password" placeholder="请输入密码" v-model="password" />
        </div>
      </div>
      <div class="itemText">
        <router-link to="/forget">忘记密码?</router-link>
      </div>
      <div class="loginBtn" @click="login(tel,password)">
        <img src="../../assets/login/login.png" alt class="img" />
        <div class="logintext">登&nbsp;&nbsp;录</div>
      </div>
      <div class="itemText">
        <router-link :to="{path:'/register',query:{pid:pid,id:id,}}">还没有账号?去注册</router-link>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      tel: "",
      password: "",
      pid: "",
      id: "",
      eabg: {
        backgroundImage:
          "url(" + require("../../assets/login/loginbg.png") + ")",
        backgroundRepeat: "no-repeat",
        backgroundSize: "100% 100%"
      }
    };
  },
  created() {
    if (this.$route.query.pid || this.$route.query.id) {
      this.pid = this.$route.query.pid;
      this.id = this.$route.query.id;
      console.log(this.pid, "跳到注册页面的时候");
    }
  },
  methods: {
    login(tel, password) {
      //return;
      if (tel == "" || tel == undefined || tel == null) {
        this.AlertWin("登录账号不能为空");
        //this.$alert('登录账号不能为空')
      } else if (password == "" || password == undefined || password == null) {
        this.AlertWin("登录密码不能为空");
        //this.$alert('登录密码不能为空')
      } else {
        var data = {
          mobile: tel,
          password: password
        };
        var url = this.$host1 + `home/login`;
        this.$axios
          .post(url, data)
          .then(res => {
            //return
            if (res.status == 200) {
              console.log(tel, "--tel", password, "--password");
              let resData = res.data;
              if (resData.code == 200) {
                console.log(res);
                //   this.getWXuserInfo();
                let isback = this.$route.query.isback;
                // console.log(isback);
                //localStorage.setItem('user_token', 123)
                if (isback == 1) {
                  this.$router.back(-1);
                } else {
                  this.AlertWin("登录成功！");
                  this.$router.push({
                    path: "/"
                  });
                }
                var phone = res.data.data.mobile;
                this.otherLogin(phone);
              } else {
                this.AlertWin(resData.message);
                //this.$toast(resData.msg);
              }
            }
          })
          .catch(() => {
            // this.AlertWin("网络错误！请稍后重试！");
            //this.$toast('网络出错,请检查网络设置');
          });
        var params = {
          user_phone: tel,
          user_password: password
        };
        console.log(params,'---params');
        this.$axios
          .post(
            `https://test.izhixiu.cn/www/met/front/login`,
            params
          )
          .then(res => {
            console.log(1)
          })
          .catch(err => {
            console.log(err, "err-----");
          });
      }
    },
    getWXuserInfo() {
      let url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx4d891cfd89a934e7&redirect_uri=https%3a%2f%2ftest.izhixiu.cn%2fwww%2fmet%2fmusicstore%2f&response_type=code&scope=snsapi_base&#wechat_redirect`;
      window.location.href = url;
    }
  }
};
</script>
<style lang="scss">
.register {
  width: 100%;
  height: 100vh;
  overflow: hidden;
  .loginbg {
    width: 100%;
    height: 100%;
    overflow: hidden;
  }
  .loginConent {
    width: 100%;
    height: auto;
    position: absolute;
    left: 0;
    top: 0;
    padding: 0.58rem 0.4rem;
    box-sizing: border-box;
    .loginTop {
      width: 7.02rem;
      margin: 0 auto;
      display: flex;
      align-items: center;
      .logo {
        width: 0.78rem;
        height: 0.78rem;
        // background-color: #297ef2;
        border-radius: 0.14rem;
      }
      .logotext {
        font-size: 0.4rem;
        color: #666666;
        margin-left: 0.28rem;
      }
    }
    .content {
      margin: 0 auto;
      margin-top: 1.55rem;
      .item {
        width: 5.4rem;
        height: 1.5rem;
        display: flex;
        align-items: center;
        border-bottom: 0.01rem solid #e9e9e9;
        .itemimg {
          width: 0.44rem;
          height: 0.46rem;
        }
        input {
          width: 5.4rem;
          border: 0;
          outline: 0;
          background: none;
          height: 0.8rem;
          margin-left: 0.1rem;
          //margin-top: 30px;
          font-size: 0.32rem;
          color: #999999;
        }
        .iconfont {
          font-size: 0.48rem;
          color: #5a01a3;
          margin-top: 0.1rem;
        }
        .tel {
          font-size: 0.5rem;
        }
      }
      .item1 {
        width: 4.7rem;
      }
      .item2 {
        width: 3.7rem;
      }
    }
    .itemText {
      font-size: 0.28rem;
      color: #5a01a3;
      text-align: left;
      margin-top: 0.3rem;
      a {
        text-decoration: none;
        color: #5a01a3;
      }
    }
    .loginBtn {
      width: 5.4rem;
      height: 1rem;
      margin-top: 1.1rem;
      display: flex;
      align-items: center;
      position: relative;
      .img {
        width: 5.4rem;
        height: 1rem;
      }
      .logintext {
        font-size: 0.32rem;
        color: #f5f5f5;
        position: absolute;
        // top:0;
        left: 1.5rem;
      }
    }
  }
}
</style>
